package com.chanyachting.emall.action.companyproduct;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.MultipartRequestHandler;

import com.chanyachting.emall.domain.Sellyacht;
import com.chanyachting.emall.form.SellyachtForm;
import com.chanyachting.emall.service.CompanyproductService;
import com.chanyachting.emall.service.SellyachtService;
import com.chanyachting.emall.serviceImpl.CompanyproductServiceImpl;
import com.chanyachting.emall.serviceImpl.SellyachtServiceImpl;
import com.chanyachting.emall.util.DateUtil;


//创建游艇销售
public class UpdateSellyachtAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		SellyachtForm syform=(SellyachtForm)form;
		
		MultipartRequestHandler mm = form.getMultipartRequestHandler();
		Hashtable h = mm.getTextElements();
		
		Iterator iter = h.entrySet().iterator();
		
		while(iter.hasNext()) {
			Map.Entry entry  = (Map.Entry)iter.next();
			String val[] = (String[]) entry.getValue();
			System.out.println("key=" + entry.getKey() + ";value=" + val[0]);
		}
		
		try {
			
			Sellyacht sy=new Sellyacht();
			CompanyproductService cpservice=new CompanyproductServiceImpl();
			SellyachtService sellService=new SellyachtServiceImpl();
			
			BeanUtils.copyProperties(sy, syform);
			int id = sy.getId();
			Sellyacht tmpSy = sellService.QueryOneSellyacht(String.valueOf(id));
			
			sy.setCreateDate(tmpSy.getCreateDate());
			sy.setUpdateDate(DateUtil.getDate());
			sy.setTitle(sy.getName());
			sy.setStatus("00");
			
			cpservice.updateCompanyproduct(sy);
			
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		
		
		return mapping.findForward("updateSellyacht");
	}
	
	
	

}
